package com.jiuwan.gamepass.controller;

import com.jiuwan.gamepass.dto.appJson.IconJson;
import com.jiuwan.gamepass.pojo.IconApp;
import com.jiuwan.gamepass.service.impl.IconServiceImpl;
import com.jiuwan.gamepass.utils.MyCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @version 1.0
 * 功能目的描述 ：用于  上传icon   ========>>>>>>>>>>>
 * @author： pang-yun
 * @date： 2021-06-08 10:59
 */

@Controller
@RequestMapping("icon")
public class IconController {

    @Autowired
    private IconJson iconJson;
    @Autowired
    private IconServiceImpl iconService;


    //上传icon图片
    @RequestMapping("uploadIcon")
    @ResponseBody
    public IconJson uploadIcon(MultipartFile[] files,String appID) {
        IconJson iconJson = iconService.uploadIcon(files,appID);
        return iconJson;
    }


    //根据app的uuid来查询所有的icon
    @RequestMapping("selectIcon")
    @ResponseBody
    public IconJson selectIcon(String appID){
        List<IconApp> iconApps = iconService.selectIcon(appID);
        iconJson.setCode(MyCode.SUCCESS_CODE);
        iconJson.setMsg(MyCode.SUCCESS_MSG);
        iconJson.setIcons(iconApps);
        return iconJson;
    }


    //根据app的uuid来删除所有的icon
    @RequestMapping("deleteIcon")
    @ResponseBody
    public IconJson deleteIcon(String appID){
        IconJson iconJson = iconService.deleteIcon(appID);
        return iconJson;
    }

    //更新Icon
    @RequestMapping("updateIcon")
    @ResponseBody
    public IconJson updateIcon(MultipartFile[] files,String appID){
        iconService.deleteIcon(appID);
        IconJson iconJson = iconService.uploadIcon(files, appID);
        return iconJson;
    }
}
